function SocketApp() {

    this.socket = null;

    this.connect = function (ipAddress) {
        // console.log(this,ipAddress)
        // console.log(window)
        // console.log(window.io.connect(ipAddress))
        // console.log(window.WebSocke)
        this.socket = window.io.connect(ipAddress);
       // console.log(this)
    }

    this.sendMessage = function (data) {
        if (!this.socket) {
            console.log("please connect first!")
            return;
        }
        if (data ) {
            this.socket.send(data);
            // console.log('send',JSON.stringify(data) );
        } else {
            console.log("please emit data")
        }
    }

    this.getMessage = function(tag,callback){
        if (!this.socket) {
            console.log("please connect first!")
            return;
        }

        this.socket.on(tag, function (msg) {
            // console.log(tag,msg)
            if(callback){
                callback(msg);
            }
           
        })

        // // 监听消息
        //     this.socket.addEventListener('message', function (event) {
        //         console.log('Message from server ', event.data);
        //     // });
        //     })
    }

}

export default SocketApp; 
